package vg.services.graph_layout_manager.interfaces;

import com.google.common.collect.Maps;
import vg.services.progress_manager.interfaces.IProgressTask;
import vg.services.progress_manager.realization.InfinityProgressTask;

import java.util.Map;

/**
 * Abstract class for layout with a lot of standard methods.
 *
 * @author Timur Zolotuhin (tzolotuhin@parallels.com)
 */
public abstract class ABaseGraphLayout implements IGraphLayout {
    // Mutex
    protected final Object generalMutex = new Object();

    // Main data
    protected Map<String, Object> settings = Maps.newHashMap();
    protected InfinityProgressTask progressTask;

    protected ABaseGraphLayout(String name) {
        progressTask = new InfinityProgressTask(name);
    }

    @Override
    public void setSettings(Map<String, Object> settings) {
        synchronized (generalMutex) {
            this.settings = settings;
        }
    }

    @Override
    public Map<String, Object> getSettings() {
        synchronized (generalMutex) {
            return settings;
        }
    }

    @Override
    public IProgressTask getProgress() {
        synchronized (generalMutex) {
            return progressTask;
        }
    }

    @Override
    public String getName() {
        return progressTask.getTaskName();
    }
}
